home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / sources.arc / DANG_SRC.LZH / SEL2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-13  |  18.6 KB  |  737 lines

  1. /*  loads up main selection screen
  2.  
  3.     user can select 
  4.  
  5.        1 -enter city
  6.        2 -load char
  7.        3 -save char
  8.        4 -roll a char     
  9.    */
  10.  
  11. struct character
  12.         {
  13.          char name[15]; /* NO! Set these to char *name and then */
  14.          char align[15]; /* name = "blahh.." OR do char name[]="blah!" */
  15.          char class[15];  /* you're defining an array of one element */
  16.          int lvl;         /* thats a ptr to a char! too redundant! */
  17.          long int exp;
  18.          long int hp;
  19.          int ac,str,inte,wis,dex,con;
  20.          int weapon_num,armor_num;
  21.          int backpack[10];       /* holds unique #. I'll have 1 
  22.                                     main array that will hold number,
  23.                                     name so we can look it up. Set to -1, means EMPTY */
  24.          char weapon[15];
  25.          char armor[15];
  26.          char spell[15];
  27.          long int max_hp,max_sp;
  28.          int spell_num;
  29.          long int sp;
  30.          long int gold;
  31.          int user_items[25];  /* holds food,h2o,keys,etc.. */
  32.          int current_spells_active[5]; /*0=treasure Finding, 1=Fleetness, 2=Protection
  33.                                          3=Strength 4=Charm */
  34.          int hunger_thurst_status[2];  /*0 not hungry/thirsty.. 10 FAMISHED */
  35.                                        /* 0 is hunger 1 is thirst */
  36.          long int bank_balance;  
  37.          int x_loc,y_loc,        /* current x,y location */
  38.              weather,count,way,time,loc,current_sky,
  39.              current_sound,clock,am_pm,sound;
  40.          char dir; 
  41.          };
  42.  
  43.  
  44.  struct character user;
  45.  char name[20],align,class;
  46.  
  47.  
  48. int  buffer[200];        /* holds the char info for disk loading and saving */
  49. int pointer[37];
  50.  
  51.  
  52.  
  53. #define rnd(t) abs(Random()%(t))   /*returns a number from 0 to (t-1) */
  54.  
  55. char     temp_[32000],                     /* Temp buffer where file is read in    */
  56.          *hld,
  57.          *iff_in, *iff_out;                  /* Pointers for DEGAS unpack() routine    */
  58.  
  59. #include <stdio.h>
  60. #include <gemdefs.h>
  61. #include <osbind.h>
  62.  
  63. int contrl[12];
  64. int intin[256],  ptsin[256];
  65. int intout[256], ptsout[256];
  66.  
  67.  
  68. int savepal[16],newpal[16],junkbuff[46];
  69. int filehandle;
  70. char input[] = "select.dat";
  71. int handle;
  72. int button,x,y;
  73. int stats[10];
  74. int choice;           /* if == 1 then you rolled and accepted a character */
  75.  char pix1[]  ="START0.DAT";
  76.  char pix2[]  ="START1.DAT";
  77.  
  78.  
  79. main()
  80.  
  81. {
  82.     char command[20];
  83.     char *scr1,*scr2,*scr3,*screen;
  84.     char in;
  85.     int type;
  86.    
  87.     MFDB    theMFDB;    /*  Screen definition structure  */
  88.     char string[30];
  89.  
  90.     appl_init();
  91.     handle = open_workstation(&theMFDB);
  92.     
  93. v_hide_c(handle);   /*hide the mouse */
  94.  
  95. pt_set(pointer,4,2);
  96. pointer[2]=1;
  97. pointer[3]=3;
  98. pointer[4]=2;
  99. stuffbits(&pointer[5],"0000000000000000");
  100. stuffbits(&pointer[6],"0001111100000000");
  101. stuffbits(&pointer[7],"0001111000000000");
  102. stuffbits(&pointer[8],"0001000110000000");
  103. stuffbits(&pointer[9],"0000000001100000");
  104. for(type=10;type<21;type++)
  105. stuffbits(&pointer[type],"0000000000000000");
  106.  
  107. stuffbits(&pointer[5],"0000000000000000");
  108. stuffbits(&pointer[6],"0011111000000000");
  109. stuffbits(&pointer[7],"0011110000000000");
  110. stuffbits(&pointer[8],"0011001110000000");
  111. stuffbits(&pointer[9],"0000000011100000");
  112. for(type=10;type<21;type++)
  113. stuffbits(&pointer[type],"0000000000000000");
  114.  
  115.  
  116.    scr1 = malloc(32768+256);  /*allocate memory for 2nd screen */
  117.     if ((long) scr1 & 0xff)
  118.       scr1 = scr1 + (0x100 - (long)scr1 & 0xff);
  119.  
  120. screen = (char *)Physbase();          /* get ptr to physbase */
  121. type = 2; /* *.pc1 pic */
  122.  
  123. read_stuff(pix1,scr1,type);   /* intro screen */
  124. Setscreen(scr1,scr1,-1);    /* display the pic */
  125. Setpalette(newpal);        /* tel sys to use these colors! */
  126. in=Bconin(2);
  127. fade_to_black();
  128.  
  129. Setscreen(screen,screen,-1);
  130. read_stuff(pix2,scr1,type);   /* title screen */
  131. Setscreen(scr1,scr1,-1);    /* display the pic */
  132. Setpalette(newpal);        /* tel sys to use these colors! */
  133. in=Bconin(2);
  134. fade_to_black();
  135.  
  136. Setscreen(screen,screen,-1);
  137. read_stuff(input,scr1,type);  /* Selection screen onto the temp scr*/
  138. Setscreen(scr1,scr1,-1);    /* display the pic */
  139. Setpalette(newpal);        /* tel sys to use these colors! */
  140.  
  141. vsc_form(handle,pointer);  /* make our new mouse ptr active */
  142. v_show_c(handle,0);
  143.  do                              /* loop until keypress */
  144.      {
  145.      
  146.   vq_mouse(handle,&button,&x,&y);
  147.  
  148.  
  149.   if(button == 1 && (x>14 && x<42))         /* if left button pressed... */
  150.       {
  151.        if( y>35 && y<61) enter_city(scr1);
  152.        if( y>67 && y<93) {Setscreen(screen,screen,-1);
  153.                           intro(); 
  154.                           Setscreen(scr1,scr1,-1);
  155.                           Setpalette(newpal); }
  156.        if( y>100 && y<127) save_character();
  157.        if( y>134 && y<161) roll();
  158.       }
  159.      } while ( 1 );      /* while no input */
  160. Setscreen(screen,screen,-1);  
  161. Setpalette(savepal);      /* restore palette */
  162.     v_clsvwk(handle);
  163.     appl_exit();
  164. }
  165.  
  166.  
  167.  
  168. /*************************/
  169. intro()
  170. {
  171.  FILE *ofp;
  172.  char c,com;
  173.  int y=0;
  174.  
  175.  for(y=0;y<27;y++) printf("                                         \n");
  176.  y=0;
  177.  ofp = fopen("intro.txt","r");
  178.   
  179.    while( (c=getc(ofp)) != EOF)
  180.    { printf("%c",c);
  181.      if(c == '\n') y++;
  182.     if(y == 23) { printf("\n -- MORE --"); com = Bconin(2); y=0; 
  183.           vs_curaddress(handle,50,0);printf("                     \n");}
  184.       }
  185.   if(c == EOF){ printf("\n -- DONE --"); com = Bconin(2);}
  186.  
  187.  
  188. }
  189.  
  190.  
  191. /************************************/
  192. save_character()
  193. {
  194. FILE *ofp;
  195. char out;
  196. int x;
  197.  
  198. clear();
  199. v_gtext(handle,188,37,"Save a Character");
  200. savechar(buffer);
  201. v_gtext(handle,188,53,"Character saved");
  202.  
  203.  
  204. }
  205.  
  206.  
  207. /******************************8/
  208. stats[] 
  209. */         
  210. roll()
  211.  
  212. {
  213. int x;
  214. char c;
  215.  
  216. clear();
  217. v_gtext(handle,188,37,"Roll a Character");
  218.  
  219. do
  220. {
  221. choice = 0;          /* reset choice to 0 */
  222.  
  223. user.lvl = 1;
  224. user.exp = 0L;
  225. user.ac  = 15;
  226. user.weapon_num = 0;
  227. user.armor_num = 0;
  228. user.spell_num = 0;
  229. user.bank_balance = 0L;
  230. user.x_loc = 19;               /* x,y location */
  231. user.y_loc = 16;
  232. user.weather = 0;
  233. user.time = 0;
  234. user.count = 1;
  235. user.way = 1;
  236. user.loc = 206;       /* initial room # */
  237. user.current_sky = 0;
  238. user.current_sound = 0;
  239. user.sound = 1;
  240. user.clock = 1;
  241. user.am_pm = 1;
  242. user.dir = 'N';       /* face north! */
  243.  
  244. for(x=0;x<10;x++) user.backpack[x] = -1;
  245. for(x=0;x<25;x++) user.user_items[x] = 0;
  246. for(x=0;x<2;x++) user.hunger_thurst_status[x] = 0;
  247.  
  248. user.str = user.inte = user.wis = user.dex = user.con = 10; /* base */
  249. user.str  += rnd(8);
  250. user.inte += rnd(8);
  251. user.wis  += rnd(8);
  252. user.dex  += rnd(8);
  253. user.con  += rnd(8);
  254.  
  255. user.hp = user.sp = user.gold = 5L; /* base */
  256. user.hp += (long int) rnd(20);
  257. user.sp += (long int) rnd(20);
  258. user.gold += (long int) rnd(20);
  259.  
  260. user.max_hp = user.hp;
  261. user.max_sp = user.sp;
  262.  
  263. strcpy(user.weapon,"None");
  264. strcpy(user.armor,"None");
  265. strcpy(user.spell,"None");
  266.  
  267. display();
  268.  
  269. v_gtext(handle,188,141,"Accept");
  270. v_gtext(handle,248,141,"Reroll");
  271.  
  272.  do               /* loop until mouse press */
  273.      {
  274.      
  275.       vq_mouse(handle,&button,&x,&y);
  276.       if( button == 1 && (y>133 && y<150))  /* if left button pressed and in y range */ 
  277.          {
  278.          
  279.           if(x > 187 && x<230) choice = 1;  /* accept!! */
  280.           if(x >247 && x < 320) choice = -1; /* reroll */
  281.          }
  282.      }while(choice == 0);
  283.  
  284. }while(choice == -1);     /* reroll */
  285.  
  286. v_hide_c(handle);   /*hide the mouse */
  287.  
  288.  
  289. if( choice == 1 )
  290.   {
  291.     clear();
  292.     vs_curaddress(handle,7,30);
  293.     v_gtext(handle,188,54,"Name:");
  294.     while ( (Bconstat(2)) == -1) c =Bconin(2);
  295.     scanf("%s",name);
  296.     clear();
  297.     v_gtext(handle,188,53,"Alignment:");
  298.     v_gtext(handle,188,61,"G)ood");
  299.     v_gtext(handle,188,69,"N)eutral");
  300.     v_gtext(handle,188,77,"E)vil");
  301.     do
  302.     {
  303.     align = Bconin(2);
  304.     } while( (align != 'G' && align != 'g')  && (align != 'N' && align != 'n') 
  305.              && (align != 'E' && align != 'e') );
  306.     clear();
  307.     v_gtext(handle,188,53,"Class:");
  308.     v_gtext(handle,188,61,"F)ighter");
  309.     v_gtext(handle,188,69,"M)age");
  310.     v_gtext(handle,188,77,"T)hief");
  311.    
  312.    do
  313.     {
  314.     class = Bconin(2);
  315.     } while( (class != 'F' && class != 'f')  && (class != 'M' && class != 'm') 
  316.              && (class != 'T' && class != 't') );
  317.  
  318.  
  319.  
  320.     strcpy(user.name,name);
  321.     if(align == 'G' || align == 'g') strcpy(user.align,"Good");
  322.     if(align == 'N' || align == 'n') strcpy(user.align,"Neutral");
  323.     if(align == 'E' || align == 'e') strcpy(user.align,"Evil");
  324.     if(class == 'F' || class == 'f') strcpy(user.class,"Fighter");
  325.     if(class == 'M' || class == 'm') strcpy(user.class,"Mage");
  326.     if(class == 'T' || class == 't') strcpy(user.class,"Thief");
  327.     clear();
  328.     v_gtext(handle,188,53,"Be sure to SAVE");
  329.     v_gtext(handle,188,61,"your character..");
  330.     
  331.   }
  332.  v_show_c(handle,0);
  333. }
  334. /****************************/
  335. display()
  336. {
  337.  char string[30];
  338.  
  339.  
  340. clear();
  341. v_gtext(handle,188,53,user.name);
  342. v_gtext(handle,188,61,user.align);
  343. v_gtext(handle,188,69,user.class);
  344. if(user.str < 10)
  345. sprintf(string,"     STR: %d",user.str);
  346. else
  347. sprintf(string,"     STR:%d",user.str);
  348. v_gtext(handle,188,77,string);
  349.  
  350. if(user.dex < 10)
  351. sprintf(string,"     DEX: %d",user.dex);
  352. else
  353. sprintf(string,"     DEX:%d",user.dex);
  354. v_gtext(handle,188,85,string);
  355.  
  356. if(user.inte < 10)
  357. sprintf(string,"     INT: %d",user.inte);
  358. else
  359. sprintf(string,"     INT:%d",user.inte);
  360. v_gtext(handle,188,93,string);
  361.  
  362. if(user.wis < 10)
  363. sprintf(string,"     WIS: %d",user.wis);
  364. else
  365. sprintf(string,"     WIS:%d",user.wis);
  366. v_gtext(handle,188,101,string);
  367.  
  368. if(user.con < 10)
  369. sprintf(string,"     CON: %d",user.con);
  370. else
  371. sprintf(string,"     CON:%d",user.con);
  372. v_gtext(handle,188,109,string);
  373.  
  374.  
  375. if(user.hp < 10L)
  376. sprintf(string,"     HP : %ld",user.hp);
  377. else
  378. sprintf(string,"     HP :%ld",user.hp);
  379. v_gtext(handle,188,117,string);
  380.  
  381. if(user.sp < 10L)
  382. sprintf(string,"     SP : %ld",user.sp);
  383. else
  384. sprintf(string,"     SP :%ld",user.sp);
  385. v_gtext(handle,188,125,string);
  386.  
  387. }
  388. /****************************/
  389. clear()
  390. {
  391.  int h,y=37;
  392.  
  393.  
  394.      
  395. for(h=0;h<14;h++)
  396. {
  397. v_gtext(handle,188,y,"                ");
  398. y +=8;
  399. }
  400.  
  401. }
  402. /***************************/
  403. enter_city(scr1)
  404. char *scr1;
  405. {
  406.  
  407. clear();
  408. v_hide_c(handle);   /*hide the mouse */
  409. free(scr1);
  410. clear();
  411. v_gtext(handle,188,45,"Loading....");
  412. Pexec(0,"CITY","","");
  413. exit(1);                        /* and quit when exit city */
  414.    
  415.  }
  416.  
  417.  
  418.  
  419. /* load degas compressed pics */
  420.  
  421. /************************/
  422. read_stuff(hold,adrr,type)
  423. char hold[];
  424. register char *adrr;
  425. int type;
  426.  
  427. {
  428.  char buf[130];
  429.  int lines,i;
  430.  
  431.  
  432. filehandle = Fopen(hold,0); 
  433.  
  434. for(i=0; i<16;i++)
  435.  savepal[i]=Setcolor(i,-1);
  436.  
  437. /* read header data */
  438. i=Fread(filehandle,2L,buf);
  439.  
  440.  
  441. /* read 16 words(32 bytes) of palette data into newpal array */
  442. i =Fread(filehandle,32L,newpal);
  443.  
  444.  
  445. if(type == 1)                       /* if .pi1 pic */
  446.  {
  447.    i =Fread(filehandle,32000L,adrr);/* read pic image in */ 
  448.    /* Close file */
  449.    Fclose(filehandle);
  450.    return(1);                       /* and quit */
  451.  } 
  452.  
  453.                                    /* else it's compressed.. */
  454. i=Fread(filehandle,32000L,temp_);  /* read image onto back screen*/
  455. /* Close file */
  456. Fclose(filehandle);
  457.  
  458.                                   
  459.  
  460.      lines = 200;                     /* Low, med-res    */
  461.                  iff_in  = temp_;                /* iff_in pts to temp_buf*/
  462.                  iff_out = adrr;      /* iff_out pts to pic_buffer*/
  463.                   do        
  464.          unpack(0);                                      /* Unpack a line at a time */
  465.                   while (--lines); 
  466.  
  467.     
  468. }
  469. /************************/
  470.  
  471. /***********************/
  472.  
  473. /*---------------------------------------------------------------------------*/
  474. /*                             |--------- DEGAS ---------|            */
  475. /*                              UNCOMPRESSED   COMPRESSED            */
  476. /*                 NEO  low med mono   low med mono     TINY    */
  477. /*    typ...        0     1   2   3     4   5   6     7        */
  478.  
  479. /* Unpacks a single scan line & updates iff_in & iff_out global pointers
  480.  
  481.                      /    byt ==  0 to  127  copy next [byt+1] bytes
  482. Unpack routine --if-<    byt == -1 to -127  copy next byte [-byt+1] times
  483.                      \    byt == 128         NO-OP                            */
  484.  
  485. unpack(rez)
  486. int     rez;
  487.  
  488. {
  489.     register char     *src_ptr, *dst_ptr,           /* ptrs to source/dest */
  490.               byt, cnt;                     /* byt holds the ACTUAL compressed data code(control byte ) */
  491.     register int      minus128 = -128, 
  492.               len;                          
  493.     char                 linbuf[320];                            /* Oversize just in case! */
  494.     int                      llen;
  495.  
  496.  
  497.     if (rez < 2)     len = 160;
  498.     else             len = 80;
  499.     llen = len;
  500.     src_ptr = iff_in;           /* iff_in is ptr to compressed data */
  501.     dst_ptr = &linbuf[0];       /* linbuf WILL hold an ENTIRE Uncompressed scan line. 4 bitplanes * 80 = 320 max! */ 
  502.  
  503.     while (len > 0)
  504.    {
  505.             byt = *src_ptr++;       /* get byte value at address scr_ptr, THEN inc scr_ptr+1 */
  506.             if (byt >= 0)           /* If ctrl code >= 0 then use the next x+1 bytes*/
  507.     {
  508.                  ++byt;                 /* inc byt +1 */
  509.                   do 
  510.        {
  511.                         *dst_ptr++ = *src_ptr++;  /* get byte value from address source, and inc the 2 ptrs */
  512.                         --len;                    /* one byte down.. */
  513.                    }
  514.          while (--byt);           /* do this byt TIMES (remember byt here = byt+1 */
  515.              }
  516.              else 
  517.        if (byt != minus128)       /* else if ctrl code NOT = -128*/
  518.          {                        /*Then use the next byte -x+1 times, (-x) cause x will be negative and - - = + */
  519.                       cnt = -byt + 1;         /* cnt = -x + 1 */
  520.                       byt = *src_ptr++;       /* byt = THE very next byte past the ctrl code(or ctrl byte! */
  521.                        do {
  522.                                *dst_ptr++ = byt;  /* store that byte */
  523.                                --len;         
  524.                           }
  525.                while (--cnt);    /* keep doing it cnt times */
  526.                   }
  527.         }
  528.  
  529.     ilbm_st(linbuf, iff_out, rez);   /* convert the format line */
  530.     iff_in = src_ptr;                                    /* Update global pointers */
  531.     iff_out += llen;
  532.  
  533. }                                /* end of module uncompress() */
  534.  
  535. /*---------------------------------------------------------------------------*/
  536.  
  537. ilbm_st(src_ptr, dst_ptr, rez)           /* Convert ILBM format line to ST format */
  538. int         *src_ptr, *dst_ptr, rez;
  539. {
  540.     int         x, *p0_ptr, *p1_ptr, *p2_ptr, *p3_ptr;
  541.  
  542.     if (rez==0) 
  543.  {                                                     /* Low-res */
  544.   
  545.         p0_ptr = src_ptr;
  546.         p1_ptr = src_ptr + 20;
  547.         p2_ptr = src_ptr + 40;
  548.         p3_ptr = src_ptr + 60;
  549.         for (x=0; x<20; ++x)
  550.   {
  551.                *dst_ptr++ = *p0_ptr++;
  552.                *dst_ptr++ = *p1_ptr++;
  553.                *dst_ptr++ = *p2_ptr++;
  554.                *dst_ptr++ = *p3_ptr++;
  555.           }
  556.     } 
  557.  else if (rez==1) 
  558.   {                                            /* Med-res */
  559.            p0_ptr = src_ptr;
  560.            p1_ptr = src_ptr + 40;
  561.            for (x=0; x<40; ++x)
  562.     {
  563.                  *dst_ptr++ = *p0_ptr++;
  564.                  *dst_ptr++ = *p1_ptr++;
  565.             }
  566.     }
  567.     else 
  568.      {                                                   /* Monochrome */
  569.               for (x=0; x<40; ++x)
  570.                   *dst_ptr++ = *src_ptr++;
  571.          }
  572.  
  573.  }
  574. /*---------------------------------------------------------------------------*/
  575.  
  576.  
  577. fade_to_black()
  578. {
  579.  int h;
  580.  
  581.   for(h=0;h<16;h++)
  582.     Setcolor(h,0x000);
  583.  
  584.    }
  585. /**********************/
  586.  
  587.  
  588. /* 
  589.   the load and save character routines.
  590.  
  591. */
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599. /*********************/
  600. /* ints are 2 bytes
  601.    chars are 1 byte 
  602.    longs are 4 bytes 
  603.  
  604.    ALL strings must be terminated with \0 or NULL!!!
  605.  
  606. */
  607.  
  608. savechar(b)
  609. int b[];
  610. {
  611. int pp,k,fd;
  612.  
  613.  
  614.  
  615.   strcpy(b,user.name);
  616.   strcpy(&b[15],user.align);
  617.   strcpy(&(b[30]),user.class);
  618.   b[45] = user.lvl;
  619.  
  620.   
  621.   extract_LW_into_two_words( user.exp,&(b[46])  , &(b[48]));
  622.     
  623.  
  624.   b[51] = user.ac;
  625.   extract_LW_into_two_words( user.hp , &(b[52]) , &(b[54]) );
  626.  
  627.   b[56]=user.str;
  628.   b[57]=user.inte;
  629.   b[58]=user.wis;
  630.   b[59]=user.dex;
  631.   b[60]=user.con;
  632.   b[61]=user.weapon_num;
  633.   b[62]=user.armor_num;
  634.   for(k=0;k<10;k++)
  635.    b[63+k]=user.backpack[k];
  636.   
  637.   strcpy(&(b[73]),user.weapon);
  638.   strcpy(&(b[88]),user.armor);
  639.   strcpy(&(b[103]),user.spell);
  640.  
  641.   extract_LW_into_two_words( user.max_hp , &(b[118]) , &(b[120]) );
  642.   extract_LW_into_two_words( user.max_sp , &(b[122]) , &(b[124]) );
  643.  
  644.   b[126]=user.spell_num;
  645.  
  646.   
  647.   extract_LW_into_two_words( user.sp , &(b[127]) , &(b[129]) );
  648.  
  649.   extract_LW_into_two_words( user.gold , &(b[131]) , &(b[133]) );
  650.  
  651.  
  652.   for(k=0;k<25;k++)
  653.    b[135+k]=user.user_items[k];
  654.   for(k=0;k<5;k++)
  655.    b[160+k]=user.current_spells_active[k];
  656.   for(k=0;k<2;k++)
  657.    b[165+k]=user.hunger_thurst_status[k];
  658.    
  659. extract_LW_into_two_words( user.bank_balance , &(b[168]) , &(b[170]) );
  660.  
  661.  
  662.   b[173]=user.x_loc;   /* global x&y coords _ OTHERS*/
  663.   b[174]=user.y_loc;
  664.   b[175]=user.weather;
  665.   b[176]=user.count;
  666.   b[177]=user.way;
  667.   b[178]=user.time;
  668.   b[179]=user.loc;
  669.   b[180]=user.current_sky;
  670.   b[181]=user.current_sound;
  671.   b[182]=user.clock;
  672.   b[183]=user.am_pm;
  673.   b[184]=user.sound;
  674.   b[185]=user.count;
  675.   b[186]=user.dir;
  676.  
  677.  if( (fd = Fopen("char.dat",1)) < 0) printf("\nError cant open file\n"); 
  678.  
  679.  Fwrite(fd,(long)400,b); /*write 400 bytes to file */
  680.  
  681.  Fclose(fd);
  682.  
  683.  
  684. }
  685.  
  686. /*************************************************************/
  687.  
  688.  
  689. extract_LW_into_two_words( data , MSW , LSW )
  690. long int data;
  691.      int *MSW,*LSW;
  692.  
  693. /* This procedure will take a longword(data) and break
  694.    it up into 2 words
  695.  
  696.    Input: data --> the long word
  697.   Output: MSW  --> the Most Signifigant Word
  698.           LSw  --> the Least Sig. Word
  699.  
  700.  
  701. */
  702. {
  703.  long int result; 
  704.  
  705.                                    /* Extract MSW */
  706.   result = data & 0xffff0000;
  707.   result = result >> 16;
  708.    *MSW = result;                        /* store it in an int */
  709.  
  710.  result = data & 0x0000ffff;          /* extract LSW */
  711.  *LSW = result;                          /*store it */
  712.   
  713.  
  714.  }
  715.  
  716. /**********************************************************/
  717.  
  718. create_LW_from_two_words( result, MSW, LSW )
  719. /* Creates a long word from two words */
  720. long int *result;
  721.      int MSW,LSW;
  722. {
  723.  long int lower_word;
  724.                                  /* This code will form a long int
  725.                                    from 2 ints */
  726.  *result = MSW;                        /* get MSW */
  727.  *result = *result << 16;                 /* put into upper word */
  728.  lower_word = LSW;                          /* get LSW */
  729.  lower_word = lower_word & 0x0000ffff;          /* it gets sign extended, so mask
  730.                                        out upper word */
  731.  
  732.  *result +=lower_word;                       /* add to get final result */
  733.  
  734.  
  735.  
  736. }
  737.